package com.changgou.business.listener;

import okhttp3.*;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.io.IOException;

@Component
public class AdListener {

    //表示监听的是add_update_queue这个队列
    @RabbitListener(queues = "add_update_queue")
    public void resviceMessage(String message){
        System.out.println("接收到的消息为:" + message);

        //进行远程的信息的调用
        OkHttpClient okHttpClient = new OkHttpClient();
        String url = "http://192.168.200.128/ad_update?position="+message;
        Request request = new Request.Builder().url(url).build();
        Call call = okHttpClient.newCall(request);
        call.enqueue(new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {
                //当前的请求是失败的
                e.printStackTrace();
            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                //当前的请求是成功的
                System.out.println("请求成功!"+ response.message());
            }
        });
    }
}
